package com.didispace.web;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.cloud.context.scope.refresh.RefreshScopeRefreshedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.didispace.MyBean;
import com.didispace.MyBean2;
import com.didispace.User;

@RefreshScope
@RestController
class TestController {

    @Value("${from}")
    private String from;

    @Autowired
    User user;
    @Autowired
    MyBean mybean;
    @Autowired
    MyBean2 mybean2;
    
    @PostConstruct
    public void init(){
    	System.out.println("initial TestController");
    }
    @RequestMapping("/from")
    public String from() {
    	System.out.println(user.getName()+user.getAge());
    	mybean.doing();
    	mybean2.doing();
        return this.from;
    }

    public void setFrom(String from) {
        this.from = from;
    }

    public String getFrom() {
        return from;
    }
    
//    @EventListener(RefreshScopeRefreshedEvent.class)
//    public void refreshBean(RefreshScopeRefreshedEvent event){
//    	System.out.println("event happened:"+event);
//    }

}